package com.geovis.emergency.spd.controller.pc;


import com.geovis.common.core.api.Result;
import com.geovis.common.core.constant.SwaggerConstants;
import com.geovis.common.core.controller.BaseController;
import com.geovis.common.mybatis.page.PageParam;
import com.geovis.common.mybatis.page.PageResult;
import com.geovis.emergency.spd.biz.agora.AgoraTokenDTO;
import com.geovis.emergency.spd.biz.pc.service.IPcDiscussService;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDiscussDTO;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDiscussQueryDTO;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDiscussSaveDTO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 应急预案指挥模块-研判会商 前端控制器
 * </p>
 *
 * @author 曾德实
 * @since 2022-05-01
 */
@RestController
@RequestMapping("/pc/pcDiscuss")
@RequiredArgsConstructor
@Api(value = "应急预案指挥模块-研判会商接口", tags = "应急预案指挥模块-研判会商接口")
@Slf4j
@Validated
public class PcDiscussController extends BaseController<IPcDiscussService> {

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = SwaggerConstants.SAVE_VALUE, notes = SwaggerConstants.SAVE_VALUE)
    @PostMapping({"/save"})
    public Result<String> save(@RequestBody PcDiscussSaveDTO saveDTO) {

        if(!StringUtils.hasText(saveDTO.getPcDrillId()))
        {
            return Result.failed("演练ID不能为空");
        }
        if(!StringUtils.hasText(saveDTO.getTitle()))
        {
            return Result.failed("会议名称不能为空");
        }
        if(!StringUtils.hasText(saveDTO.getContent()))
        {
            return Result.failed("会议主题不能为空");
        }
        if(CollectionUtils.isEmpty(saveDTO.getStaffIdList()))
        {
            return Result.failed("会议人员列表不能为空");
        }

        baseService.save(saveDTO);
        return Result.ok();
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "进入会议", notes = "进入会议")
    @ApiImplicitParams({@ApiImplicitParam(name = "pcDiscussId", value = "会议id", required = true, dataType = "java.lang.String")})
    @PostMapping({"/join/{pcDiscussId}"})
    public Result<AgoraTokenDTO> join(@PathVariable("pcDiscussId") String pcDiscussId) {
        return Result.ok(baseService.join(pcDiscussId));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "结束会议", notes = "结束会议")
    @ApiImplicitParams({@ApiImplicitParam(name = "pcDiscussId", value = "会议id", required = true, dataType = "java.lang.String")})
    @PostMapping({"/finish/{pcDiscussId}"})
    public Result<String> finish(@PathVariable("pcDiscussId") String pcDiscussId) {
        baseService.finish(pcDiscussId);
        return Result.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "离开会议", notes = "离开会议")
    @ApiImplicitParams({@ApiImplicitParam(name = "pcDiscussId", value = "会议id", required = true, dataType = "java.lang.String")})
    @PostMapping({"/leave/{pcDiscussId}"})
    public Result<String> leave(@PathVariable("pcDiscussId") String pcDiscussId) {
        baseService.leave(pcDiscussId);
        return Result.ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = SwaggerConstants.LIST_VALUE, notes = SwaggerConstants.LIST_VALUE)
    @PostMapping("/list")
    public Result<List<PcDiscussDTO>> list(@RequestBody PcDiscussQueryDTO queryDTO) {
        return Result.ok(baseService.list(queryDTO));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = SwaggerConstants.LIST_PAGE_VALUE, notes = SwaggerConstants.LIST_PAGE_VALUE)
    @PostMapping("/listPage")
    public Result<PageResult<PcDiscussDTO>> listPage(@RequestBody PageParam<PcDiscussQueryDTO> pageParam) {
        return Result.ok(baseService.listPage(pageParam));
    }

}
